﻿using System;

namespace BankSystem
{
    public class ATM
    {
        Bank Bank;
        public event Action<string, decimal> BigMoneyFetched;
        public ATM(Bank bank)
        {
            Bank = bank;
        }

        /// <summary>
        /// 
        /// </summary>
        public void Transaction()
        {
            Show("please insert your card");
            string id = Console.ReadLine();
            Show("please enter your password");
            string pwd = Console.ReadLine();
            Account account = Bank.FindAccount(id, pwd);
            if (account == null)
            {
                Show("card invalid or password not corrent");
                return;
            }
            Show("1: display; 2: save; 3: withdraw");
            string op = Console.ReadLine();
            if (op == "1")
            {
                Show("balance: " + account.Money);
            }
            else if (op == "2")
            {
                Show("save money");
                string smoney = Console.ReadLine();
                decimal money = decimal.Parse(smoney);
                bool ok = account.SaveMoney(money);
                if (ok) Show("ok");
                else Show("eeer");
                Show("balance: " + account.Money);
            }
            else if (op == "3")
            {
                Show("withdraw money");
                string smoney = Console.ReadLine();
                decimal money = decimal.Parse(smoney);
                bool ok = account.WithdrawMoney(money);
                if (money > 10000)
                {
                    BigMoneyFetched?.Invoke(account.Id, money);
                }
                if (ok) Show("ok");
                else Show("eeer");
                Show("balance: " + account.Money);
            }
        }

        public void Show(string msg)
        {
            Console.WriteLine(msg);
        }

    }
}
